﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;

namespace SofiaSKGTwp7
{
    public partial class LineResults : PhoneApplicationPage
    {
        public LineResults()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            App AppCls = (Application.Current as App);

            if (State.ContainsKey("STNAME"))
                State.Remove("STNAME");
            State.Add("STNAME", AppCls.STNAME);

            if (State.ContainsKey("resHOURS"))
                State.Remove("resHOURS");
            State.Add("resHOURS", AppCls.resHOURS);

            if (State.ContainsKey("resLINE"))
                State.Remove("resLINE");
            State.Add("resLINE", AppCls.resLINE);


            base.OnNavigatedFrom(e);
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            App AppCls = (Application.Current as App);

            try
            {
                if(State.ContainsKey("resHOURS"))
                {
                    AppCls.resHOURS = State["resHOURS"].ToString();
                }

                if (State.ContainsKey("resLINE"))
                {
                    AppCls.resLINE = State["resLINE"].ToString();
                }

                if (State.ContainsKey("STNAME"))
                {
                    AppCls.STNAME = State["STNAME"].ToString();
                }

            }
            catch (Exception exp)
            {
                MessageBox.Show("Couldn't resotre the desired page! \r\n" + exp.Message);
            }

            tbStationText.Text += "\r\n"+AppCls.STNAME;

            if (AppCls.resHOURS != "")
            {
                tbArrTime.Text += AppCls.resHOURS;
            }

            if (AppCls.resLINE != "")
            {
                tbLineNum.Text += AppCls.resLINE;
            }

            base.OnNavigatedTo(e);
        }
    }
}